package easy.springioc.ioc;

import easy.springioc.context.support.ClassPathXmlApplicationContext;
import easy.springioc.entity.HelloWorld;

public class TestEasySpringIOC {

    public static void main(String[] args) throws Exception{
        // 读取bean xml配置文件
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("helloioc.xml");

        // 按id获取：   根据bean id 获取bean
        Object getBeanById = applicationContext.getBeanById("world1");
        System.out.println("world1: "+ getBeanById);

        // 按name获取：  根据bean name 获取bean
        Object getBeanByName = applicationContext.getBeanByName("helloWorld");
        System.out.println("helloWorld: "+ getBeanByName);

        // 按type获取： 根据bean class 获取bean
        Object getBeansOfType = applicationContext.getBeansOfType(HelloWorld.class);
        System.out.println("HelloWorld.class: "+ getBeansOfType);

        // 测试依赖注入
        Object world2 = applicationContext.getBeanById("world2");
        System.out.println("world2: "+ world2);

        HelloWorld helloWorldInstance = (HelloWorld) world2;
        System.out.println(helloWorldInstance.getPerson());
    }
}
